import abc
from .mirrordb import MirrorDB

from .tsmirror_setting import token,db_url
import tushare as ts


class CachedManager(abc.ABC):
    def __init__(self):
        pass

    @abc.abstractmethod
    def checkcacheflag(self,paramdict):
        pass

    @abc.abstractmethod
    def updatecacheflag(self,paramdict):
        pass

    @abc.abstractmethod
    def loadcacheflag(self):
        pass

    @abc.abstractmethod
    def savecacheflag(self):
        pass

class Warpper:
    _singleton_pro_instance = None

    # def __new__(cls):
    #     print("new")
    #     if cls._singleton_pro_instance is None:
    #         ts.set_token(token)
    #         _singleton_pro_instance=123 #ts.pro_api()
    #
    # def getproinstance(self):
    #     if self.__class__._singleton_pro_instance is None:
    #         self.__new__()
    #     return self.__class__._singleton_pro_instance

    def __init__(self):
        self.db=MirrorDB(db_url)
        self.value=1

class Warpper2:
    _singleton_pro_instance = None

    def __new__(cls, *args, **kwargs):
        if cls._singleton_pro_instance is None:
            cls._singleton_pro_instance = super().__new__(cls)
        return cls._singleton_pro_instance

    def getproinstance(self):
        if self.__class__._singleton_pro_instance is None:
            self.__new__()
        return self.__class__._singleton_pro_instance

    def __init__(self, value):
        try:
            self._initialized
        except AttributeError:
            self.__new__(self.__class__)
            self._initialized = True
        self.db = mirrordb.MirrorDB(db_url)
        self.value = value




# Example Usage
if __name__ == "__main__":
    wapper=Warpper()
    print(wapper)